local skel = fk.CreateSkill {
  name = "rmt__hongdang",
}

Fk:loadTranslationTable{
  ["rmt__hongdang"] = "鸿荡",
  [":rmt__hongdang"] = "持恒技，游戏开始时，你获得20点神人值；如下情况时，你获得对应数量的神人值：当一名角色受到1点雷电伤害后——" ..
  "5点；当你弃置牌后——10点；当你回复1点体力后——15点。<br>你根据神人值视为拥有以下技能：25点-〖星变〗；50点-〖如律〗；75点-〖连篇〗；" ..
  "99点-〖云叠〗。你的神人值上限为99。",

  ["@rmt__hongdang_shenren"] = "神人值",

  ["$rmt__hongdang1"] = "貂蝉元出兜鍪，神人本自凡夫。",
  ["$rmt__hongdang2"] = "娟娟隔秋水，濯足洞庭兮望八荒。",
}

skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if player:getMark("@rmt__hongdang_shenren") >= 25 and not player:hasSkill("rmt_hongdang__xingbian") then
    room:handleAddLoseSkills(player, "mobile_skel__qingzheng")
  end
  if player:getMark("@rmt__hongdang_shenren") >= 50 and not player:hasSkill("rmt_hongdang__rulv") then
    room:handleAddLoseSkills(player, "mobile_skel__jiushi")
  end
  if player:getMark("@rmt__hongdang_shenren") >= 75 and not player:hasSkill("rmt_hongdang__lianpian") then
    room:handleAddLoseSkills(player, "mobile_skel__fangzhu")
  end
  if player:getMark("@rmt__hongdang_shenren") >= 99 and not player:hasSkill("rmt_hongdang__yundie") then
    room:handleAddLoseSkills(player, "juejin")
  end
end)

skel:addLoseEffect(function (self, player, is_death)
  local room = player.room
  room:setPlayerMark(player, "@rmt__hongdang_shenren", 0)
  room:handleAddLoseSkills(player, "-rmt_hongdang__xingbian|-rmt_hongdang__rulv|-rmt_hongdang__lianpian|-rmt_hongdang__yundie")
end)

local function ChangeDaoxin(player, num)
  local room = player.room
  local daoxin = player:getMark("@rmt__hongdang_shenren")
  num = math.min(99 - daoxin, num)
  if num > 0 then
    room:setPlayerMark(player, "@rmt__hongdang_shenren", daoxin + num)
    if player:getMark("@rmt__hongdang_shenren") >= 25 and not player:hasSkill("rmt_hongdang__xingbian") then
      room:handleAddLoseSkills(player, "rmt_hongdang__xingbian")
    end
    if player:getMark("@rmt__hongdang_shenren") >= 50 and not player:hasSkill("rmt_hongdang__rulv") then
      room:handleAddLoseSkills(player, "rmt_hongdang__rulv")
    end
    if player:getMark("@rmt__hongdang_shenren") >= 75 and not player:hasSkill("rmt_hongdang__lianpian") then
      room:handleAddLoseSkills(player, "rmt_hongdang__lianpian")
    end
    if player:getMark("@rmt__hongdang_shenren") >= 99 and not player:hasSkill("rmt_hongdang__yundie") then
      room:handleAddLoseSkills(player, "rmt_hongdang__yundie")
    end
  end
end

skel:addEffect(fk.GameStart, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player:getMark("@rmt__hongdang_shenren") < 99
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ChangeDaoxin(player, 20)
  end,
})

skel:addEffect(fk.Damaged, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player:getMark("@rmt__hongdang_shenren") < 99 and
      data.damageType == fk.ThunderDamage
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ChangeDaoxin(player, 5 * data.damage)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and player:getMark("@rmt__hongdang_shenren") < 99 then
      for _, move in ipairs(data) do
        if move.from == player and move.moveReason == fk.ReasonDiscard then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ChangeDaoxin(player, 10)
  end,
})

skel:addEffect(fk.HpRecover, {
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player:getMark("@rmt__hongdang_shenren") < 99
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ChangeDaoxin(player, 15 * data.num)
  end,
})

return skel
